use crate::bootstrap::AppState;
use axum::{extract::OriginalUri, http::StatusCode, response::IntoResponse, Router};
use resp::RespVO;

mod album;
pub mod errors;
pub mod resp;
use self::album::album_route;

pub async fn create_routes(state: AppState) -> Router<AppState> {
    let route = Router::new()
        .nest("/album", album_route(state.clone()))
        .fallback(handler_404);
    route
}

// pub async fn create_routes(state: AppState) -> Router<AppState> {
//     let route = Router::new()
//         .nest("/auth", auth_route(state.clone()))
//         .nest("/user", user_route(state.clone()))
//         .fallback(handler_404);
//     route
// }

async fn handler_404(uri: OriginalUri) -> impl IntoResponse {
    let error_url = uri.to_string();
    tracing::error!(" handler_404 : {} ", error_url);
    RespVO::<()>::from_error(
        Some(StatusCode::NOT_FOUND.as_u16()),
        format!(
            "URL {} The requested resource was not found",
            error_url.as_str()
        )
        .to_string(),
        None,
    )
}
